﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using WebEntities;

namespace com.subb.WebInformation
{
    public class NewsQuery
    {
        public static readonly Func<WebsiteDbEntities, int, int, IQueryable<WI_News>> GetAllNewsQuery =
            CompiledQuery.Compile((WebsiteDbEntities context, int start, int limit) =>
                context.WI_News.OrderByDescending(c => c.SortNum ?? 0).ThenByDescending(c => c.NewsID).Skip(start).Take(limit));

        public static readonly Func<WebsiteDbEntities, int, int, int, IQueryable<WI_News>> GetAllNewsQueryByCata =
            CompiledQuery.Compile((WebsiteDbEntities context, int cataId, int start, int limit) =>
                context.WI_News.Where(c => c.CataID == cataId).OrderByDescending(c => c.SortNum ?? 0)
                    .ThenByDescending(c => c.NewsID).Skip(start).Take(limit));

        public static readonly Func<WebsiteDbEntities, int, int, int, IQueryable<WI_News>> GetAllNewsQueryByParentCata =
            CompiledQuery.Compile((WebsiteDbEntities context, int pcataId, int start, int limit) =>
                context.WI_News.Where(c => c.WI_NewsCata.ParentCataID == pcataId).OrderByDescending(c => c.SortNum ?? 0)
                    .ThenByDescending(c => c.NewsID).Skip(start).Take(limit));

        public static readonly Func<WebsiteDbEntities, int?, int, int, IQueryable<WI_NewsCata>> GetAllNewsCataQueryByPcata =
            CompiledQuery.Compile((WebsiteDbEntities context, int? pcataId, int start, int limit) =>
                context.WI_NewsCata.Where(c => c.ParentCataID == pcataId).OrderByDescending(c => c.SortNum ?? 0)
                    .ThenByDescending(c => c.CataID).Skip(start).Take(limit));
    }
}
